package com.hjf.ditubiaozhu.base.recycler;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.TextView;

import com.hjf.ditubiaozhu.base.Base;
import com.hjf.ditubiaozhu.base.ImageLoadHelper;


/**
 * Created by hejianfeng on 17/2/11.
 */

public abstract class MyViewHolder<T extends Base> extends RecyclerView.ViewHolder {
    public Context mContext;
    protected View mItemView;
    public T mModel;
    protected ImageLoadHelper mImageLoadHelper;

    public MyViewHolder(View itemView) {
        super(itemView);
        mItemView = itemView;
        mContext = itemView.getContext();
    }


    protected <V extends View> V findView(int id) {
        return (V) mItemView.findViewById(id);
    }
    public void setModel(T model){
        mModel = model;
        bindModel();
    }

    public abstract void bindModel();
    /**
     * 设置文本
     */
    public void setText(TextView textview, String text) {

        if (text == null) text = "";
        if (textview != null) textview.setText(text);
    }

    public void setImageLoadHelper(ImageLoadHelper imageLoadHelper) {
        mImageLoadHelper = imageLoadHelper;
    }
}
